package com.sskj.quantization.ui.activity;


import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.flyco.tablayout.SegmentTabLayout;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.sskj.common.adapter.MyFragmentPagerAdapter;
import com.sskj.common.base.App;
import com.sskj.lib.Constans;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseActivity;
import com.sskj.quantization.R;
import com.sskj.quantization.R2;
import com.sskj.quantization.presenter.RecordActivityPresenter;

import java.util.ArrayList;

import butterknife.BindView;

@Route(path = RConfig.QUAN_RECORD)
public class RecordActivity extends BaseActivity<RecordActivityPresenter> {
    @BindView(R2.id.segmentTabLayout)
    SegmentTabLayout segmentTabLayout;
    @BindView(R2.id.viewPager)
    ViewPager viewPager;

    private String titles[] = new String[]{App.INSTANCE.getString(R.string.quan_recordActivity1_h), App.INSTANCE.getString(R.string.quan_recordActivity2_h)};

    @Override
    protected int getLayoutId() {
        return R.layout.quan_activity_record;
    }

    @Override
    public RecordActivityPresenter getPresenter() {
        return new RecordActivityPresenter();
    }

    @Override
    protected void initView() {
        setTitle(App.INSTANCE.getString(R.string.quan_recordActivity3_h));
        segmentTabLayout.setTabData(titles);
        segmentTabLayout.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                viewPager.setCurrentItem(position);
            }

            @Override
            public void onTabReselect(int position) {

            }
        });
        ArrayList<Fragment> fragments = new ArrayList<>();
        fragments.add((Fragment) ARouter.getInstance().build(RConfig.QUAN_FRAGMENT_RECORD).withBoolean(Constans.IS_HOLD, true).navigation());
        fragments.add((Fragment) ARouter.getInstance().build(RConfig.QUAN_FRAGMENT_RECORD).withBoolean(Constans.IS_HOLD, false).navigation());
        viewPager.setAdapter(new MyFragmentPagerAdapter(getSupportFragmentManager(), fragments));
        viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                super.onPageSelected(position);
                segmentTabLayout.setCurrentTab(position);
            }
        });
    }
}
